package com.sskj.hangqing.presenter;

import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.common.base.HttpData;
import com.sskj.common.rxbus2.RxBus;
import com.sskj.hangqing.bean.SelfCoinBean;
import com.sskj.hangqing.ui.activity.SelfCoinAddActivity;
import com.sskj.lib.RxBusCode;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;

import java.util.List;

import io.reactivex.Flowable;


/**
 * @author Hey
 * Create at  2019/09/02 17:43:39
 */
public class SelfCoinAddPresenter extends BasePresenter<SelfCoinAddActivity> {

    public Flowable<List<SelfCoinBean>> getData(String code, int page) {
        return httpService.getSelfCoinList(code, page + "")
                .converter(new JsonConverter<HttpData<PageBean<SelfCoinBean>>>() {
                })
                .adapt(new FlowableBody<>())
                .map(haiPageBeanHttpData -> haiPageBeanHttpData.getData().getList());
    }

    public void edit(String id, boolean isAdd) {
        httpService.editSelfCoin(id, isAdd ? "2" : "1").execute(new JsonCallBack<HttpData<PageBean<SelfCoinBean>>>() {
            @Override
            public void onSuccess(Response<HttpData<PageBean<SelfCoinBean>>> response) {
                RxBus.getDefault().post(RxBusCode.REFRESH_HANGQING);
            }
        });
    }
}
